//###############
//FILE : FileInfoMessage.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############
package oop.ex3.protocol.messages;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import oop.ex3.exceptions.InvalidMessageException;

/**
 * This is the base class of all messages that send and receive filenames.
 * @author daniel
 */
public abstract class FileInfoMessage extends Message{
    String _fileName;

    /**
     * Create a new file message initialized with a header.
     * @param header The message header.
     */
    public FileInfoMessage(String header){
        super(header);
    }

    /**
     * Create a file initialized with a header and a file name to send.
     * @param header The message header.
     * @param fileName The file name to send.
     */
    public FileInfoMessage(String header, String fileName){
        super(header);
        setFileName(fileName);
    }

    /**
     * Set the file name that this message should send.
     * @param fileName The file name to send.
     */
    public void setFileName(String fileName){
        _fileName = fileName;
    }

    /**
     * Get the file name that this message received. This method should be called after
     * receiving the message.
     * @return
     */
    public String getFileName(){
        return _fileName;
    }

    protected void sendDetails(DataOutputStream outputStream) throws IOException {
        outputStream.writeUTF(_fileName);
    }

    protected void receiveDetails(DataInputStream inputStream) throws IOException, InvalidMessageException {
        _fileName = inputStream.readUTF();
    }
}
